package com.jacky.thread;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class ScheduledPoolTest {

    public static void main(String[] args) {
        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);

        Runnable oneTimeTask = () -> {
            System.out.println("One-time delayed task executed!");
        };

        // 一次性延迟执行任务，延迟时间为 2 秒
        executorService.scheduleAtFixedRate(oneTimeTask, 1,2, TimeUnit.SECONDS);

        // 关闭线程池
       // executorService.shutdown();
    }
}
